<template>
  <div class="my container">
    <header>
      <div class="userInfo" v-if="loginStatus">
        <img :src="userInfo.imgUrl" alt="" />
        <span>{{ userInfo.nickName }}</span>
      </div>
      <div class="login" @click="goLogin" v-else>登录/注册</div>
    </header>
    <section>
      <ul>
        <li @click="goAddress">地址管理</li>
        <li v-if="loginStatus" @click="loginOut">退出登录</li>
      </ul>
    </section>
    <Tabbar></Tabbar>
  </div>
</template>

<script>
import Tabbar from "@/components/common/Tabbar.vue";
import { mapMutations, mapState } from "vuex";
export default {
  components: { Tabbar },
  name: "My",
  methods: {
    goLogin() {
      this.$router.push("/login");
    },
    //进入地址管理
    goAddress() {
      // this.$router.push("/address");
      this.$router.push("/address");
    },
    //退出登录
    ...mapMutations(["loginOut"]),
    // refresh() {
    //   location.reload(true);
    //   return;
    // },
  },
  // created() {
  //   this.refresh();
  // },
  computed: {
    ...mapState({
      loginStatus: (state) => state.user.loginStatus,
      userInfo: (state) => state.user.userInfo,
    }),
  },
};
</script>

<style scoped lang="scss">
.my {
  header {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 4.266666rem;
    background-color: #b0352f;
    .login {
      padding: 0.16rem 0.4rem;
      font-size: 0.4266666rem;
      color: #fff;
      background-color: #f6ab32;
      border-radius: 6px;
    }
    .userInfo {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      img {
        width: 1.76rem;
        height: 1.76rem;
        border-radius: 100%;
      }
      span {
        padding: 0.533333rem 0;
        color: #fff;
        font-size: 0.48rem;
      }
    }
  }
  section {
    flex: 1;
    overflow: hidden;
    ul li {
      padding: 0.4rem;
      font-size: 0.4266666rem;
    }
  }
}
</style>